<%@page import="java.util.ArrayList"%>
<%@page import="ext.csc.component.numbergen.loader.LoadReporter"%>
<%@page import="ext.csc.component.numbergen.loader.NumberTranslated"%>
<%@page import="ext.csc.component.numbergen.loader.DataSource"%>
<%@page import="ext.csc.component.numbergen.loader.NumberLoader"%>
<%@page import="ext.csc.component.numbergen.loader.NumberLoaderTranslator"%>
<%@page import="ext.csc.component.numbergen.loader.ExcelFileDataSource"%>
<%@page import="ext.csc.component.numbergen.utilities.FileUploader"%>
<%@page import="ext.csc.component.numbergen.bean.PropertiesBean"%>
<%@page import="wt.util.WTProperties"%>
<%@page import="java.util.Vector"%>
<%@page import="java.io.File"%>
<%
	PropertiesBean pb = new PropertiesBean();
	//FileUploader uploader = new FileUploader(pageContext, pb.getValue("FileUploadingPath"));
	WTProperties wtp = WTProperties.getLocalProperties();
	String WT_HOME = wtp.getProperty("wt.home");
	String PATH = WT_HOME + File.separator + "temp";
	FileUploader uploader = new FileUploader(pageContext, PATH);
	
	Vector filePaths = uploader.getFilesPath();
	String filepath = (String)(filePaths.get(filePaths.size()-1));
	ExcelFileDataSource datasource = new ExcelFileDataSource(filepath);
	NumberLoaderTranslator translator = new NumberLoaderTranslator();
	
	NumberLoader loader = new NumberLoader((DataSource)datasource, (NumberTranslated)translator);
	loader.load();
	
	LoadReporter report = loader.getReporter();
	ArrayList logs = report.getLogs();
	for (int i = 0; i < logs.size(); i++) {
%>	
		<script>window.opener.document.getElementById('logBoard').value=window.opener.document.getElementById('logBoard').value + '<%=(String)(logs.get(i))%>' + '\n'</script>
<%
		System.out.println(logs.get(i));
	}
	
	ArrayList backErrors = report.getBackErrors();
	for (int i = 0; i < backErrors.size(); i++) {
		System.out.println(backErrors.get(i));
	}
	
	ArrayList errorReport = report.getDisplayErrors();
	for (int i = 0; i < errorReport.size(); i++) {
%>
		<script>window.opener.document.getElementById('errorBoard').value=window.opener.document.getElementById('errorBoard').value + '<%=(String)(errorReport.get(i))%>' + '\n'</script>
<%
	}
%>
	<script>
		window.open('','_self');  
		window.opener=null;
		window.close();
	</script>